/**
 * Created by ecervetti on 05/03/2014.
 */


Sprite = function(urlFile,finalwidth,finalheight) {
    var thisSprite = this ;
    thisSprite.image = new Image() ;
    thisSprite.image.src = urlFile ;
    thisSprite.image.onload = function(){
        if(finalwidth>0) {
            thisSprite.canvas = document.createElement('canvas');
            thisSprite.canvas.width = finalwidth ;
            thisSprite.canvas.height = finalheight ;
            var context = thisSprite.canvas.getContext('2d');
            context.rect(0,0,finalwidth,finalheight);
            context.fillStyle="rgba(255,255,255,0)";
            context.fill();
            context.drawImage(thisSprite.image, 0, 0,finalwidth,finalheight );
        } else {
            thisSprite.canvas = thisSprite.image ;
        }
        //Image DATA copie ce qu'on voit à l'écran sur le canvas, et ne conserve pas la transparence du canvas
        //thisSprite.imagedata = context.getImageData(0, 0, finalwidth, finalheight);
        thisSprite.ready = true ;
    };
};

Sprite.prototype = {
  image : null ,
  ready : false ,
  canvas : null
};